package RofMission;

import main.PlanesProp;
import main.Prop;
import missObjects.AirplaneUse;
import missObjects.RofMissObjAirfield;


/**
 * Handle mission parameters (object selection margin, plane types and load,...
 * @author lefuneste
 *
 */
public class RofMissionParams {
	//version
	String version="RofTOALMG v1.0";
	double windSpeedLimit=5;
	
	//objects selection
	double Xmin=0;
	double Xmax=0;
	double Zmin=0;
	double Zmax=0;
	double Xmargin=5000; 
	double Zmargin=5000;
	int flagAirfieldOnly=1;
	
	
	//default position for player plane
	double playerXPos=49540; 
	double playerYPos=128;
	double playerZPos=58170;

	//meteo
	int precLevel=0;
	int precType=0;
	int turbulence=0;
	double tempPressLevel=0;
	int temperature = 15;
	int pressure = 760;	
	// wind blowing TO windDir
	int windSpeed=5;
	int windDir=0;
	
	//default planes models & scripts
	String playerPlaneModel;
	String landingPlaneModel;
	String takeoffPlaneModel;
	String playerScript="\"LuaScripts\\WorldObjects\\spad13.txt\"";
	String playerModel="\"graphics\\planes\\spad13\\spad13.mgm\"";
	String landingScript="\"LuaScripts\\WorldObjects\\breguet14.txt\"";
	String landingModel="\"graphics\\planes\\breguet14\\breguet14.mgm\"";
	String takeoffScript="\"LuaScripts\\WorldObjects\\re8.txt\"";
	String takeoffModel="\"graphics\\planes\\re8\\re8.mgm\"";
	
	//defautl AI level
	int AILevel=1;
	//default payload
	int landingPayload=0;
	int takeoffPayload=0;
	//default fuel
	double landingFuel=1;
	double takeoffFuel=1;
	
	//informations for landing
	double landSpawnDist=1000;
	double landSpawnAlt=500;
	int area=100;
	int speed=120;
	int forceReverseLanding=1;
	
	//informations for flights (landing)
	int numberOfPlaneLanding=1;
	double landingSeparation=100;
	
	//informations for takeoff
	double takeoffDist=500;
	int numberOfPlaneTakeoff=2;
	double takeoffSpacing=20;
	double takeOffEgressDist=2000;
	
	//filenames
	String rofPath="C:\\Program Files\\Rise of Flight";
	String reportfileName="F:\\TEMP\\RoF\\Report.txt";
	String missionName=rofPath+"\\data\\missions\\LandingTakeoffTest.Mission";
	String missionLog="C:\\TEMP\\Rof\\log.txt";
	String GTPPath="C:\\TEMP\\RoF\\GTP";
	
	//map Name
	String currentMap="standard";
	
	//briefing
	String briefing="x";
	
	
	/**
	 * Load params value from properties file
	 */
	public void initFromProps() {
		Xmargin=Double.parseDouble(Prop.get("Xmargin"));
		Zmargin=Double.parseDouble(Prop.get("Zmargin"));
		Xmin=Double.parseDouble(Prop.get("Xmin"));
		Zmin=Double.parseDouble(Prop.get("Zmin"));
		Xmax=Double.parseDouble(Prop.get("Xmax"));
		Zmax=Double.parseDouble(Prop.get("Zmax"));		
		precLevel=Integer.parseInt(Prop.get("precLevel"));
		precType=Integer.parseInt(Prop.get("precType"));
		turbulence=Integer.parseInt(Prop.get("turbulence"));
		tempPressLevel=Double.parseDouble(Prop.get("tempPressLevel"));
		temperature = Integer.parseInt(Prop.get("temperature"));
		pressure = Integer.parseInt(Prop.get("pressure"));
		windSpeed=Integer.parseInt(Prop.get("windSpeed"));
		windDir=Integer.parseInt(Prop.get("windDir"));		
		playerXPos=Double.parseDouble(Prop.get("playerXPos"));
		playerYPos=Double.parseDouble(Prop.get("playerYPos"));
		playerZPos=Double.parseDouble(Prop.get("playerZPos"));
		playerPlaneModel=Prop.get("playerPlaneModel");
		landingPlaneModel=Prop.get("landingPlaneModel");
		takeoffPlaneModel=Prop.get("takeoffPlaneModel");
		AILevel=Integer.parseInt(Prop.get("AILevel"));
		landingPayload=Integer.parseInt(Prop.get("landingPayload"));
		takeoffPayload=Integer.parseInt(Prop.get("takeoffPayload"));
		landingFuel=Double.parseDouble(Prop.get("landingFuel"));
		takeoffFuel=Double.parseDouble(Prop.get("takeoffFuel"));
		landSpawnDist=Double.parseDouble(Prop.get("landSpawnDist"));
		landSpawnAlt=Double.parseDouble(Prop.get("landSpawnAlt"));
		area=Integer.parseInt(Prop.get("area"));
		speed=Integer.parseInt(Prop.get("speed"));
		forceReverseLanding=Integer.parseInt(Prop.get("forceReverseLanding"));
		numberOfPlaneLanding=Integer.parseInt(Prop.get("numberOfPlaneLanding"));
		landingSeparation=Double.parseDouble(Prop.get("landingSeparation"));
		takeoffDist=Double.parseDouble(Prop.get("takeoffDist"));
		numberOfPlaneTakeoff=Integer.parseInt(Prop.get("numberOfPlaneTakeoff"));
		takeoffSpacing=Double.parseDouble(Prop.get("takeoffSpacing"));
		takeOffEgressDist=Double.parseDouble(Prop.get("takeOffEgressDist"));
		rofPath=Prop.get("rofPath");
		reportfileName=Prop.get("reportfileName");
		missionName=Prop.get("missionName");
		missionLog=Prop.get("missionLog");
		currentMap=Prop.get("currentMap");
		GTPPath=Prop.get("GTPPath");
		briefing=Prop.get("briefing");
		flagAirfieldOnly=Integer.parseInt(Prop.get("flagAirfieldOnly"));
		
	}
	
	public void saveToProps() {
		Prop.set("Xmargin", Xmargin);
		Prop.set("Zmargin", Zmargin);
		Prop.set("Xmin", Xmin);
		Prop.set("Zmin", Zmin);
		Prop.set("Xmax", Xmax);
		Prop.set("Zmax", Zmax);
		Prop.set("precLevel", precLevel);
		Prop.set("precType", precType);
		Prop.set("turbulence", turbulence);
		Prop.set("tempPressLevel", tempPressLevel);
		Prop.set("temperature", temperature);
		Prop.set("pressure", pressure);
		Prop.set("windSpeed", windSpeed);		
		Prop.set("windDir", windDir);			
		Prop.set("playerXPos", playerXPos);
		Prop.set("playerYPos", playerYPos);
		Prop.set("playerZPos", playerZPos);
		Prop.set("playerPlaneModel", playerPlaneModel);
		Prop.set("landingPlaneModel", landingPlaneModel);
		Prop.set("takeoffPlaneModel", takeoffPlaneModel);
		Prop.set("AILevel", AILevel);
		Prop.set("landingPayload", landingPayload);
		Prop.set("takeoffPayload", takeoffPayload);
		Prop.set("landingFuel", landingFuel);
		Prop.set("takeoffFuel", takeoffFuel);	
		Prop.set("landSpawnDist", landSpawnDist);
		Prop.set("landSpawnAlt", landSpawnAlt);
		Prop.set("area", area);
		Prop.set("speed", speed);
		Prop.set("forceReverseLanding", forceReverseLanding);
		Prop.set("numberOfPlaneLanding", numberOfPlaneLanding);
		Prop.set("landingSeparation", landingSeparation);
		Prop.set("takeoffDist", takeoffDist);
		Prop.set("numberOfPlaneTakeoff", numberOfPlaneTakeoff);		
		Prop.set("takeoffSpacing", takeoffSpacing);	
		Prop.set("takeOffEgressDist", takeOffEgressDist);	
		Prop.set("rofPath", rofPath);		
		Prop.set("reportfileName", reportfileName);			
		Prop.set("missionName", missionName);		
		Prop.set("missionLog", missionLog);		
		Prop.set("currentMap", currentMap);	
		Prop.set("GTPPath", GTPPath);	
		Prop.set("briefing", briefing);
		Prop.set("flagAirfieldOnly", flagAirfieldOnly);
	}
	
	/**
	 * find if the way of takeoff or landing is reversed or standard for the airfield
	 * @param airfield
	 * @return : true direction is reversed
	 */
	public boolean isAirfieldReversed(RofMissObjAirfield airfield) {
		boolean result=false;
		
		double tmp=Math.abs( ((airfield.getOriLP()+180) % 360) -(this.getWindDir() % 360));
		if ( (tmp >= 90 && this.getWindSpeed()>0) || (this.getForceReverseLanding() && this.getWindSpeed()==0)) {
			result=true;
		}

		return result;
	}
		
	// Getter and setters
	public double getXmargin() {
		return Xmargin;
	}
	public void setXmargin(Double double1) {
		Xmargin = double1;
	}
	public double getZmargin() {
		return Zmargin;
	}
	public void setZmargin(double zmargin) {
		Zmargin = zmargin;
	}
	public double getPlayerXPos() {
		return playerXPos;
	}
	public void setPlayerXPos(double playerXPos) {
		this.playerXPos = playerXPos;
	}
	public double getPlayerYPos() {
		return playerYPos;
	}
	public void setPlayerYPos(double playerYPos) {
		this.playerYPos = playerYPos;
	}
	public double getPlayerZPos() {
		return playerZPos;
	}
	public void setPlayerZPos(int playerZPos) {
		this.playerZPos = playerZPos;
	}
	public String getPlaneScript(AirplaneUse type) {
		String script = null;
		
		switch (type) {
		case PLAYER:
			script=PlanesProp.getScript(this.playerPlaneModel);
			break;
		case TAKEOFF: 
			script=PlanesProp.getScript(this.takeoffPlaneModel);
			break;
			
		case LAND: 
			script=PlanesProp.getScript(this.landingPlaneModel);
			break;		
			
		default:
			break;
		}
		return script;
	}
	
	public void setPlaneScript(AirplaneUse type, String script) {
		switch (type) {
		case PLAYER:
			playerScript=script;
			break;
		case TAKEOFF: 
			takeoffScript=script;
			break;
		case LAND: 
			landingScript=script;
			break;		
			
		default:
			break;
		}
	}
	
	public String getPlaneModel(AirplaneUse type) {
		String model = null;
		switch (type) {
		case PLAYER:
			model=PlanesProp.getModel(this.playerPlaneModel);
			break;
		case TAKEOFF: 
			model=PlanesProp.getModel(this.takeoffPlaneModel);
			break;
			
		case LAND: 
			model=PlanesProp.getModel(this.landingPlaneModel);
			break;		
			
		default:
			break;
		}
		return model;
	}
	
	
	public void setPlaneModel(AirplaneUse type, String model) {
		switch (type) {
		case PLAYER:
			playerModel=model;
			break;
		case TAKEOFF: 
			takeoffModel=model;
			break;
			
		case LAND: 
			landingModel=model;
			break;		
			
		default:
			break;
		}
	}
	
	public int getAILevel(AirplaneUse type) {
		int level=0;
		switch (type) {
		case PLAYER:
			level=0;
			break;
			
		case TAKEOFF: 
			level=AILevel;
			break;
			
		case LAND: 
			level=AILevel;
			break;		
			
		default:
			break;
		}
		return level;
	}
	
	public void setAILevel(AirplaneUse type, int level) {
		switch (type) {
		case PLAYER:
			AILevel=level;
			break;
		case TAKEOFF: 
			AILevel=level;
			break;
			
		case LAND: 
			AILevel=level;
			break;		
			
		default:
			break;
		}
	}
	
	
	public int getPayload(AirplaneUse type) {
		int paylod=0;
		switch (type) {
		case PLAYER:
			paylod=0;
			break;
			
		case TAKEOFF: 
			paylod=takeoffPayload;
			break;
			
		case LAND: 
			paylod=landingPayload;
			break;		
			
		default:
			break;
		}
		return paylod;
	}
	
	
	public void setPayload(AirplaneUse type, int paylod) {
		switch (type) {
		case PLAYER:
			//payload=paylod;
			break;
		case TAKEOFF: 
			takeoffPayload=paylod;
			break;
			
		case LAND: 
			landingPayload=paylod;
			break;		
			
		default:
			break;
		}
	}
	
	
	public double getFuel(AirplaneUse type) {
		double fuel=0;
		switch (type) {
		case PLAYER:
			//fuel=this.fuel;
			fuel=1;
			break;
			
		case TAKEOFF: 
			fuel=this.takeoffFuel;
			break;
			
		case LAND: 
			fuel=this.landingFuel;
			break;		
			
		default:
			break;
		}
		return fuel;
	}
	
	public void setFuel(AirplaneUse type, double fuel) {
		
		switch (type) {
		case PLAYER:
			//fuel=this.fuel;
			fuel=1;
			break;
			
		case TAKEOFF: 
			takeoffFuel=fuel;
			break;
			
		case LAND: 
			landingFuel=fuel;
			break;		
			
		default:
			break;
		}
	}
	
	public double getLandSpawnDist() {
		return landSpawnDist;
	}
	public void setLandSpawnDist(double landSpawnDist) {
		this.landSpawnDist = landSpawnDist;
	}
	public double getLandSpawnAlt() {
		return landSpawnAlt;
	}
	public void setLandSpawnAlt(double landSpawnAlt) {
		this.landSpawnAlt = landSpawnAlt;
	}
	public int getArea() {
		return area;
	}
	public void setArea(int area) {
		this.area = area;
	}
	public int getSpeed() {
		return speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	public boolean getForceReverseLanding() {
		boolean result;
		if (forceReverseLanding == 1 ) result=true;
		else result=false;
		return result;
	}
	public void setForceReverseLanding(int val) {
		forceReverseLanding = val;
	}
	public int getNumberOfPlaneLanding() {
		return numberOfPlaneLanding;
	}
	public void setNumberOfPlaneLanding(int numberOfPlaneLanding) {
		this.numberOfPlaneLanding = numberOfPlaneLanding;
	}
	public double getLandingSeparation() {
		return landingSeparation;
	}
	public void setLandingSeparation(double landingSeparation) {
		this.landingSeparation = landingSeparation;
	}
	public double getTakeoffDist() {
		return takeoffDist;
	}
	public void setTakeoffDist(double takeoffDist) {
		this.takeoffDist = takeoffDist;
	}
	public String getTakeoffScript() {
		return takeoffScript;
	}
	public void setTakeoffScript(String takeoffScript) {
		this.takeoffScript = takeoffScript;
	}
	public int getNumberOfPlaneTakeoff() {
		return numberOfPlaneTakeoff;
	}
	public void setNumberOfPlaneTakeoff(int numberOfPlaneTakeoff) {
		this.numberOfPlaneTakeoff = numberOfPlaneTakeoff;
	}
	public double getTakeoffSpacing() {
		return takeoffSpacing;
	}
	public void setTakeoffSpacing(double takeoffSpacing) {
		this.takeoffSpacing = takeoffSpacing;
	}
	public double getTakeOffEgressDist() {
		return takeOffEgressDist;
	}
	public void setTakeOffEgressDist(double takeOffEgressDist) {
		this.takeOffEgressDist = takeOffEgressDist;
	}
	public String getReportfileName() {
		return reportfileName;
	}
	public void setReportfileName(String reportfileName) {
		this.reportfileName = reportfileName;
	}
	public String getRofPath() {
		return rofPath;
	}
	public void setRofPath(String rofPath) {
		this.rofPath = rofPath;
	}

	public String getMissionName() {
		return missionName;
	}

	public void setMissionName(String missionName) {
		this.missionName = missionName;
	}

	public String getMissionLog() {
		return missionLog;
	}

	public void setMissionLog(String missionLog) {
		this.missionLog = missionLog;
	}

	public String getCurrentMap() {
		return currentMap;
	}

	public void setCurrentMap(String currentMap) {
		this.currentMap = currentMap;
	}

	public String getPlayerPlaneModel() {
		return playerPlaneModel;
	}

	public void setPlayerPlaneModel(String playerPlaneModel) {
		this.playerPlaneModel = playerPlaneModel;
	}

	public String getLandingPlaneModel() {
		return landingPlaneModel;
	}

	public void setLandingPlaneModel(String landingPlaneModel) {
		this.landingPlaneModel = landingPlaneModel;
	}

	public String getTakeoffPlaneModel() {
		return takeoffPlaneModel;
	}

	public void setTakeoffPlaneModel(String takeoffPlaneModel) {
		this.takeoffPlaneModel = takeoffPlaneModel;
	}

	public String getPlayerScript() {
		return playerScript;
	}

	public void setPlayerScript(String playerScript) {
		this.playerScript = playerScript;
	}

	public String getPlayerModel() {
		return playerModel;
	}

	public void setPlayerModel(String playerModel) {
		this.playerModel = playerModel;
	}

	public String getLandingScript() {
		return landingScript;
	}

	public void setLandingScript(String landingScript) {
		this.landingScript = landingScript;
	}

	public String getLandingModel() {
		return landingModel;
	}

	public void setLandingModel(String landingModel) {
		this.landingModel = landingModel;
	}

	public String getTakeoffModel() {
		return takeoffModel;
	}

	public void setTakeoffModel(String takeoffModel) {
		this.takeoffModel = takeoffModel;
	}

	public int getAILevel() {
		return AILevel;
	}

	public void setAILevel(int aILevel) {
		AILevel = aILevel;
	}

	public String getGTPPath() {
		return GTPPath;
	}

	public void setGTPPath(String gTPPath) {
		GTPPath = gTPPath;
	}

	public void setPlayerZPos(double playerZPos) {
		this.playerZPos = playerZPos;
	}

	public double getXmin() {
		return Xmin;
	}

	public void setXmin(double xmin) {
		Xmin = xmin;
	}

	public double getXmax() {
		return Xmax;
	}

	public void setXmax(double xmax) {
		Xmax = xmax;
	}

	public double getZmin() {
		return Zmin;
	}

	public void setZmin(double zmin) {
		Zmin = zmin;
	}

	public double getZmax() {
		return Zmax;
	}

	public void setZmax(double zmax) {
		Zmax = zmax;
	}

	public int getPrecLevel() {
		return precLevel;
	}

	public void setPrecLevel(int precLevel) {
		this.precLevel = precLevel;
	}

	public int getPrecType() {
		return precType;
	}

	public void setPrecType(int precType) {
		this.precType = precType;
	}

	public int getTurbulence() {
		return turbulence;
	}

	public void setTurbulence(int turbulence) {
		this.turbulence = turbulence;
	}

	public double getTempPressLevel() {
		return tempPressLevel;
	}

	public void setTempPressLevel(double tempPressLevel) {
		this.tempPressLevel = tempPressLevel;
	}

	public int getTemperature() {
		return temperature;
	}

	public void setTemperature(int temperature) {
		this.temperature = temperature;
	}

	public int getPressure() {
		return pressure;
	}

	public void setPressure(int pressure) {
		this.pressure = pressure;
	}

	public int getWindSpeed() {
		return windSpeed;
	}

	public void setWindSpeed(int windSpeed) {
		this.windSpeed = windSpeed;
	}

	public int getWindDir() {
		return windDir;
	}

	public void setWindDir(int windDir) {
		this.windDir = windDir;
	}

	public void setXmargin(double xmargin) {
		Xmargin = xmargin;
	}

	public String getBriefing() {
		return briefing;
	}

	public void setBriefing(String briefing) {
		this.briefing = briefing;
	}

	public String getVersion() {
		return version;
	}

	public double getWindSpeedLimit() {
		return windSpeedLimit;
	}

	public boolean getFlagAirfieldOnly() {
		boolean result=false;
		if (flagAirfieldOnly ==1) {
			result=true;
		}
		return result;
	}

	public void setFlagAirfieldOnly(int flagAirfieldOnly) {
		this.flagAirfieldOnly = flagAirfieldOnly;
	}
	
	

}
